package com.tg.demo.uaa.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Rubble
 * @date 2020/8/21
 */
public class MemberUserDetails implements UserDetails {

    private Member member;

    private List<String> authorities;

    public MemberUserDetails() {
    }

    public MemberUserDetails(Member member, List<String> authorities) {
        this.member = member;
        this.authorities = authorities;
    }


    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public void setAuthorities(List<String> authorities) {
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(authorities!=null){
            List<SimpleGrantedAuthority> list = new ArrayList<>();
            for (String authority : authorities) {
                list.add(new SimpleGrantedAuthority(authority));
            }
        }
        return null;
    }

    @Override
    public String getPassword() {
        return member.getPassword();
    }

    @Override
    public String getUsername() {
        return member.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return member.isAccountNoExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return member.isAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return member.isCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return member.isEnabled();
    }


}
